import { Component } from "react";
import Header from './../component/hearder.Component' ;

import BookOrder from "./common/bookComponent";

import Store from "./../redux-demo/index";
import indexAction from "./../redux-demo/actions/actions";

import CacheComponent from "./../component/cacheComponent";

import { connect } from "react-redux";

class Book extends Component {
    constructor(){
        super()
        this.handleChange = this.handleChange.bind(this) ;
        this.freshData = this.freshData.bind(this) ;
        this.needCache = false ; //是否开启缓存
        this.state = {
            value:'' 
        }
    }
    componentDidMount(){
        console.log(this.props.history.action)
        // if(this.props.history.action != 'POP'){
            this.getBookData()
        // }
    }
    activateLasers(){
        history.go(-1)
    }
    getBookData(){
        Store.dispatch(indexAction.getBookData({
            type:'GET_BOOK_DATA' ,
            data:'最受关注'
        }))
    }
    handleChange(event){
        this.setState({
            value: event.target.value
        })
    }
    freshData(){
        if(this.props.history.action == "POP"){
            let Data = JSON.parse(window.sessionStorage.getItem(this.props.location.pathname)) || {};
            document.documentElement.scrollTop = Data.scroll
        }
    }
    render(){
        let booksData = this.props.booksData || { list : []} ;
        let { list =[] } = booksData ;
        return (
            <div>
                <Header></Header>
                <CacheComponent  freshData={this.freshData} needCache={this.needCache}>
                    <div className="page">
                         <BookOrder lists={list}></BookOrder>               
                    </div>
                </CacheComponent>
            </div>
        )
    }
}
export default connect((state) => {
    return {
        booksData:state.booksData
    }
})( Book );
